// Copyright (c) 2017 Franka Emika GmbH
// Use of this source code is governed by the Apache-2.0 license, see LICENSE
#include <iostream>

#include <franka/exception.h>
#include <franka/robot.h>

/**
 * @example echo_robot_state.cpp
 * An example showing how to continuously read the robot state.
 * 展示连续读取机器人状态
 */

int main(int argc, char** argv) {
    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " <robot-hostname>" << std::endl;
        return -1;
    }

    try {
        franka::Robot robot(argv[1]);

        size_t count = 0;
        robot.read([&count](const franka::RobotState& robot_state) {
            // 向 std::cout 输出会产生延迟, 这在一个读取状态的循环中是可以接受的,
            // 但是不能在一个控制循环中使用
            std::cout << robot_state << std::endl;
            return count++ < 100;
        });

        std::cout << "Done." << std::endl;
    } catch (franka::Exception const& e) {
        std::cout << e.what() << std::endl;
        return -1;
    }

    return 0;
}
